//
//  XMQQTableCell.m
//  XMKit
//
//  Created by chenming on 2017/12/21.
//  Copyright © 2017年 ChenXiaoMing. All rights reserved.
//

#import "XMQQTableCell.h"
#import "XMQQFrame.h"
#import "XMQQModel.h"

@interface XMQQTableCell ()
@property (nonatomic, strong) UIImageView *iconView; // 头像
@property (nonatomic, strong) UILabel *nameView; // 昵称
@property (nonatomic, strong) UILabel *timeView; // 时间
@property (nonatomic, strong) UIImageView *expertView; // 达人
@property (nonatomic, strong) UILabel *textView; // 正文
@property (nonatomic, strong) UIImageView *pictureView; // 图片
@end

@implementation XMQQTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}

- (UIImageView *)iconView{
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}

- (UILabel *)nameView{
    if (!_nameView) {
        _nameView = [[UILabel alloc] init];
    }
    return _nameView;
}

- (UILabel *)timeView{
    if (!_timeView) {
        _timeView = [[UILabel alloc] init];
    }
    return _timeView;
}

- (UIImageView *)expertView{
    if (!_expertView) {
        _expertView = [[UIImageView alloc] init];
    }
    return _expertView;
}

- (UILabel *)textView{
    if (!_textView) {
        _textView = [[UILabel alloc] init];
    }
    return _textView;
}

- (UIImageView *)pictureView{
    if (!_pictureView) {
        _pictureView = [[UIImageView alloc] init];
    }
    return _pictureView;
}

- (void)setQqFrame:(XMQQFrame *)qqFrame{
    
    _qqFrame = qqFrame;
    //设置子控件显示的内容
    [self setSubViewsContent];
    //设置子控件的frame
    [self setSubViewsFrame];
    
}

- (void)setSubViewsContent{
    
    XMQQModel *qqModel = self.qqFrame.qqModel;
    self.iconView.image = [UIImage imageNamed:qqModel.icon];
    self.nameView.text = qqModel.name;
    self.timeView.text = qqModel.time;
    
    // 如果qqModel.expert有值给图片
    if (qqModel.expert) {
        self.expertView.hidden = NO;
        self.expertView.image = [UIImage imageNamed:qqModel.expert];
    } else {
        self.expertView.hidden = YES;
    }
    if (_pictureView) {
        self.pictureView.image = [UIImage imageNamed:qqModel.picture];
    }
}

- (void)setSubViewsFrame{
    self.iconView.frame = self.qqFrame.iconFrame;
    self.nameView.frame = self.qqFrame.nameFrame;
    self.timeView.frame = self.qqFrame.timeFrame;
    self.expertView.frame = self.qqFrame.expertFrame;
    self.textView.frame = self.qqFrame.textFrame;
    self.pictureView.frame = self.qqFrame.pictureFrame;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
